package com.gzu.finalwork.admin.controller;

import com.gzu.finalwork.admin.service.NotificationSettingsService;
import com.gzu.finalwork.entity.admin.NotificationSettings;
import com.gzu.finalwork.common.utils.AjaxResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 通知设置控制器
 */
@RestController
@RequestMapping("/admin/notification-settings")
public class NotificationSettingsController {

    @Autowired
    private NotificationSettingsService notificationSettingsService;

    /**
     * 获取通知设置
     */
    @GetMapping
    public Object getNotificationSettings() {
        Map<String, Object> result = new HashMap<>();
        try {
            NotificationSettings settings = notificationSettingsService.getNotificationSettings();
            result.put("success", true);
            result.put("data", settings);
            return AjaxResult.success(result);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "获取通知设置失败：" + e.getMessage());
            return AjaxResult.error(500, result);
        }
    }

    /**
     * 更新通知设置
     */
    @PutMapping
    public Object updateNotificationSettings(@RequestBody NotificationSettings notificationSettings) {
        Map<String, Object> result = new HashMap<>();
        try {
            notificationSettingsService.updateNotificationSettings(notificationSettings);
            result.put("success", true);
            result.put("message", "更新通知设置成功");
            return AjaxResult.success(result);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "更新通知设置失败：" + e.getMessage());
            return AjaxResult.error(500, result);
        }
    }
} 